package application.view
{
	import application.model.vo.LevelVO;
	import core.Size;
	import flare.core.Pivot3D;
	import flare.materials.FlatColorMaterial;
	import flare.primitives.Cube;
	import flare.primitives.Plane;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author Tiago Salomon
	 */
	public class LevelView extends Pivot3D
	{
		private var _levelVO		:LevelVO;
		private var _floor			:FloorView;
		private var _wall			:WallView;
		private var _goal			:GoalView;
		private var _crate			:CrateView;
		
		public function LevelView() 
		{			
		}
		
		private function buildGrid():void 
		{

			for (var i:uint = 0; i < this._levelVO.grid.length; i++) 
			{
				for (var j:uint = 0; j < this._levelVO.grid[i].length; j++) 
				{
					switch (this._levelVO.grid[i][j]) 
					{
						case 0 :
							_floor = new FloorView();
							_floor.setPosition(Size.CUBE * j, 0, Size.CUBE * i);							
							this.addChild(_floor);
							break;
						case 1 :
							_floor = new FloorView();
							_floor.setPosition(Size.CUBE * j, 0, Size.CUBE * i);							
							this.addChild(_floor);
							
							_wall = new WallView();
							_wall.setPosition(Size.CUBE * j, Size.CUBE/2, Size.CUBE * i);							
							this.addChild(_wall);
							
							break;
						case 2 :
							_goal = new GoalView();
							_goal.setPosition(Size.CUBE * j, 0, Size.CUBE * i);							
							this.addChild(_goal);
							
							break;
						case 3 :
							_floor = new FloorView();
							_floor.setPosition(Size.CUBE * j, 0, Size.CUBE * i);							
							this.addChild(_floor);	
							
							_crate = new CrateView("Crate"+i+j);
							_crate.setPosition(Size.CUBE * j, Size.CUBE*3/4, Size.CUBE * i);							
							this.addChild(_crate);	
							
							break;
						case 4 :
							
							break;
					}
				}
			}
			
			SceneHolder.scene.addChild(this);			
			
		}
		
		override public function show():void 
		{
			super.show();
			
			this.buildGrid();
		}

		override public function hide():void 
		{
			super.hide();
		}
		
		public function set levelVO(value:LevelVO):void 
		{
			_levelVO = value;
		}
		
	}

}